-- ___       ________  ________  ________  ___               _________  ___  _____ ______   _______
--|\  \     |\   __  \|\   ____\|\   __  \|\  \             |\___   ___\\  \|\   _ \  _   \|\  ___ \
--\ \  \    \ \  \|\  \ \  \___|\ \  \|\  \ \  \            \|___ \  \_\ \  \ \  \\\__\ \  \ \   __/|
-- \ \  \    \ \  \\\  \ \  \    \ \   __  \ \  \                \ \  \ \ \  \ \  \\|__| \  \ \  \_|/__
--  \ \  \____\ \  \\\  \ \  \____\ \  \ \  \ \  \____            \ \  \ \ \  \ \  \    \ \  \ \  \_|\ \
--   \ \_______\ \_______\ \_______\ \__\ \__\ \_______\           \ \__\ \ \__\ \__\    \ \__\ \_______\
--    \|_______|\|_______|\|_______|\|__|\|__|\|_______|            \|__|  \|__|\|__|     \|__|\|_______|
-- banner online tools
-- https://www.bootschool.net/ascii;bsid=FB5C2059677902AEBA0B2640589E9FE8

local require  = require;
local ngx      = ngx;
local debug    = debug;
local string   = string;
local tonumber = tonumber;
local setmetatable = setmetatable
local pairs    = pairs
local type     = type
local table    = table

local table_concat     = table.concat

local math       = math
local math_floor = math.floor

local uu         = require("modules.commhm.utils");
local log        = require("modules.commhm.log");


--- CLocalTime 的特性:
--- 1.基于秒的时间格式实现,用于"00:00:00"向秒数的转换


local _M = { _VERSION = '0.12.1' }
local mt = { __index = _M }
local HOUR2SEC		= 3600
local MINUTE2SEC	= 60


---生成一个新的
---@param hour_		number	时
---@param minute_	number	分
---@param second_	number	秒
---@return table	CLocalTime
function _M.new(hour_, minute_, second_ )
	hour_   = tonumber(hour_ or 0) or 0
	minute_ = tonumber(minute_ or 0) or 0
	second_ = tonumber(second_ or 0) or 0

	--log.debug( "CLocalTime:new, hour="..hour_.."minute="..minute_.."second="..second_);
	local ins_ = {
		hour	= hour_,		---时
		minute	= minute_,		---分
		second	= second_,		---秒

		time	= hour_ * HOUR2SEC + minute_ * MINUTE2SEC + second_,
	};

	local ret_ = setmetatable(ins_, mt);
	return ret_
end


---生成一个新的 CLocalTime
---@param strTime_	string
---@return table	CLocalTime
function _M.parse(strTime_)
	--log.debug("strTime="..strTime_)
	strTime_ = strTime_ or "00:00:00"
	local list_ = uu.split(strTime_, ':')
	return _M.new(list_[1], list_[2], list_[3])
end


---换算成超过"00:00:00"的秒数,比如"01:00:01"换算成 3601
---@return number	秒数
function _M.getTime(self)
	return self.time
end


return _M;
